package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/guess-number-higher-or-lower-ii/
 * @create 2025/9/8 09:40
 * @since JDK17
 */

public class Solution94 {
    public int getMoneyAmount(int n) {
        int [][] dp = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            dp[i][i + 1] = i;
        }
        for (int l = n - 2; l > 0; l--) {
            for (int r = l + 2; r <= n; r++) {
                int ans = Integer.MAX_VALUE;
                for (int k = l; k < r; k++) {
                    ans = Math.min(ans, k + Math.max(dp[l][k - 1], dp[k + 1][r]));
                }
                dp[l][r] = ans;
            }
        }

        return dp[1][n];
    }
}
